<?php

namespace app\common\model;

use think\model\concern\SoftDelete;

class NewOrders extends \think\Model
{
    use SoftDelete;

    protected $table = 'db_new_orders';

    protected $jsonAssoc = true;

    protected $autoWriteTimestamp = true;

    protected $schema = [
        'id' => 'int',
        'create_time' => 'int',
        'update_time' => 'int',
        'delete_time' => 'int',
        'pubid' => 'varchar',
        'name' => 'varchar',
        'member_id' => 'int',
        'payment_method' => 'varchar',
        'payment_time' => 'int',
        'product_type' => 'varchar',
        'product_id' => 'int',
        'purchase_type' => 'varchar',
        'purchase_days' => 'int',
        'daily_price' => 'double',
        'total_amount' => 'double',
        'payment_amount' => 'double',
        'payment_details' => 'json',
        'product_parameters' => 'json',
        'is_payment' => 'tinyint',
        'order_number' => 'varchar',
        'is_apply_for_invoice' => 'tinyint',
    ];

    protected $json = [
        'payment_details',
        'product_parameters',
    ];

    public $getters = [
        
    ];

    /**
     * 关联模型newOrderLog
     */
    public function newOrderLog()
    {
        return $this->hasMany(NewOrderLog::class );
    }

    /**
     * 关联模型member
     */
    public function member()
    {
        return $this->belongsTo(Member::class );
    }

    /**
     * 支付时间设置器
     */
    public function setPaymentTimeAttr($value, $data)
    {
        return $value?strtotime($value):0;
    }
}
